home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeeds.ans.net!btco!newsadm
- From: Shalom Reich <sqr1874@acf4.nyu.edu>
- Newsgroups: comp.lang.c++
- Subject: Re: C++ questions - please help
- Date: Thu, 21 Mar 1996 14:12:22 -0500
- Organization: Bankers Trust Company
- Message-ID: <3151AA16.EAB@acf4.nyu.edu>
- References: <4irp34$b6q@GRAPEVINE.LCS.MIT.EDU>
- NNTP-Posting-Host: algsvw0058.btco.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (WinNT; I)
-
- Frank Kim wrote:
- >
- > Question #1:
- > [snip]
- >
- > and its constructor looks like this:
- >
- > faxRmApp::faxRmApp() : request("remove") {}
- >
- > I don't understand why the request("remove") initialization is outside
- > the brackets.
- >
-
- All initialization of member data and/or base classes for constructors should
- be done in the initialization list (between the ":" after the end of the parm list
- and before the "{" of the function body) instead of inside the function body.
- This is usually done for performance purposes but there can be other reasons as
- well (i.e. initializing a virtual base class, initializing a reference).
-
- (See C++ Primer by Lippman or Effective C++ by Scott Meyer.)
-
- >
- > Question #2
- >
- > Why does the scope of the external declaration not extend beyond the
- > inner block?
- >
-
- The whole purpose of scope is to limit visibility of variables. The extern
- has more to do with storage life time and location (i.e. static and allocated
- elsewhere). The variable may have storage allocated to it but I may not want
- it to be changed just anywhere (possibly by accident).
-
- >
- > Question #3
- >
- > Is there any difference between these two declarations?
- >
- > char *s1 = "hello";
- > char s2[] = "hello";
- >
-
- I believe that the first one only allocates a pointer that is initialized to
- the address of the first byte of the string "hello". I believe that the second
- one allocates space for six chars and initializes them to the value "hello\0".
-
- Shalom Reich
-